package com.example.parkdemo.login

import androidx.lifecycle.MutableLiveData
import com.example.base.db.ParkDataBase
import com.example.base.db.UserDap
import com.example.base.mvvm.BaseViewModel
import com.example.base.net.ApiService
import com.example.base.user.UserBean
import dagger.hilt.android.lifecycle.HiltViewModel
import okhttp3.RequestBody
import javax.inject.Inject

@HiltViewModel
class LoginViewModel @Inject constructor(
    val apiService: ApiService,
    val db: ParkDataBase
) : BaseViewModel() {
    val loginSuccess by lazy { MutableLiveData<String>() }
    fun login(body: RequestBody) {
        executeNetWork(
            { apiService.login(body) },
            loginSuccess::postValue
        )
    }

    val inserUserInfoSuccess by lazy { MutableLiveData<String>() }
    fun insertUserInfo(userBean: UserBean) {
        executeDb(
            {
                db.getUserDao().DeleteUserInfo(userBean)
                "添加成功"
            },
            inserUserInfoSuccess::postValue
        )
    }
}